//https://www.nowcoder.com/practice/18ecd0ecf5ef4fe9ba3f17f8d00d2d66?tpId=122&tqId=33668&ru=/exam/oj

#include <iostream>
using namespace std;
int n;
int main()
{
	cin >> n;
	int a = 0, b = 1, c = 1;
	while (n > c)
	{
		a = b;
		b = c;
		c = a + b;
	}
	cout << min(c - n, n - b) << endl;
	return 0;
}

//https://www.nowcoder.com/practice/987f2981769048abaf6180ed63266bb2?tpId=196&tqId=39583&ru=/exam/oj

class Solution
{
	int m, n;
	bool vis[101][101] = { 0 };
	int dx[4] = { 0, 0, 1, -1 };
	int dy[4] = { 1, -1, 0, 0 };
public:
	bool exist(vector<string>& board, string word)
	{
		m = board.size(), n = board[0].size();
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (board[i][j] == word[0])
				{
					if (dfs(board, i, j, word, 0)) return true;
				}
			}
		}
		return false;
	}
	bool dfs(vector<string>& board, int i, int j, string& word, int pos)
	{
		if (pos == word.size() - 1)
		{
			return true;
		}
		vis[i][j] = true;
		for (int k = 0; k < 4; k++)
		{
			int a = i + dx[k], b = j + dy[k];
			if (a >= 0 && a < m && b >= 0 && b < n && !vis[a][b] && board[a][b]
				== word[pos + 1])
			{
				if (dfs(board, a, b, word, pos + 1)) return true;
			}
		}
		vis[i][j] = false;
		return false;
	}
};

//https://www.nowcoder.com/practice/e671c6a913d448318a49be87850adbcc?tpId=290&tqId=39928&ru=/exam/oj

#include <iostream>
using namespace std;
int dp[31][31];
int main()
{
	int n;
	cin >> n;
	dp[1][1] = 1;
	for (int i = 2; i <= n; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			printf("%5d", dp[i][j]);
		}
		printf("\n");
	}
	return 0;
}